<template>
    <div>
        <base-list ref="jobTerminal" :condition="condition" :datas.sync="jobTerminal" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="80px">
                <el-row>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="设备名称">
                            <auto-search-resource searchType="JOB_ZD" searchName="resourceName"
                                                  @selectName="v=>condition['search_LIKE_resourceName']=v"></auto-search-resource>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="设备类型">
                            <auto-search-dic @selectName="v=>condition['search_LIKE_typeName']=v" code="JOB_ZD"
                                             :name="condition['search_LIKE_typeName']"></auto-search-dic>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5" class="search-width4">
                        <el-form-item label="是否有效">
                            <el-select v-model="condition['search_EQ_valid']" placeholder="请选择" clearable>
                                <el-option v-for="[key, val] in _dictValidType" :key="key" :label="val"
                                           :value="key"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="2">
                        <el-button type="primary" icon="el-icon-search" @click="loadData" class="ml-80">查 询</el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-row slot="status">
                <el-row>
                    <el-col :span="24">
                        <el-button type="primary" formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WJOB_BASEMGR_TERMINAL:ADD')">
                            新增
                        </el-button>
                    </el-col>
                </el-row>
            </el-row>
            <el-table slot="list" :data="jobTerminal" border stripe max-height="550">
                <el-table-column prop="resourceName" label="终端设备名称"  min-width="130"></el-table-column>
                <el-table-column prop="typeName" label="终端设备类型"  min-width="130"></el-table-column>
                <el-table-column prop="ipv4" label="终端设备IP"  min-width="120"></el-table-column>
                <el-table-column prop="orgName" label="所属单位"  min-width="200"></el-table-column>
                <el-table-column prop="deptName" label="所属部门"  min-width="140"></el-table-column>
                <el-table-column prop="valid" label="是否有效"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.valid | _filterValidType }}
                    </template>
                </el-table-column>
                <el-table-column prop="status" label="是否登录"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.status | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column prop="mountTime" label="登录时间"  min-width="160"></el-table-column>
                <el-table-column prop="machine" label="绑定作业机械"  min-width="160"></el-table-column>
                <el-table-column prop="resourceDescribe" label="备注"  min-width="200"></el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <!-- v-if="power('WJOB_BASEMGR_TERMINAL:UPD')" -->
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)">
                            编辑
                        </el-button>
                         <!-- v-if="power('WJOB_BASEMGR_TERMINAL:DEL')" -->
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <job-terminal-form ref="jobTerminalForm" @load="loadData"></job-terminal-form>
    </div>
</template>

<script>
    import { deleteJobTerminal, getJobTerminalList } from "@/api/baseResource/baseResource";
    import autoSearchOrg from '@/components/autocomplete/autoSearchOrg'
    import autoSearchDic from '@/components/autocomplete/autoSearchDic'
    import autoSearchResource from '@/components/autocomplete/autoSearchResource'
    import jobTerminalForm from './jobTerminalForm'

    export default {
        name: "终端管理",
        components: {
            jobTerminalForm,
            autoSearchOrg,
            autoSearchDic,
            autoSearchResource
        },
        data() {
            return {
                condition: {}, // 查询条件
                jobTerminal: [], // table数组
                pageSearch: getJobTerminalList, // 分页查询api接口
                id: ''
            }
        },
        mounted() {
            this.$nextTick(() => {
                this.loadData()
            })
        },
        methods: {
            loadData() {
                this.$refs.jobTerminal.loadData()
            },
            handleDialogFormOpen(bool, item) {
                if (bool) {
                    let form = JSON.parse(JSON.stringify(item))
                    this.$refs.jobTerminalForm.form = {
                        id:form.id,
                        resourceName: form.resourceName,
                        typeName: form.typeName,
                        typeCode: form.typeCode,
                        typeId: form.typeId,
                        ipv4: form.ipv4,
                        valid: form.valid,
                        resourceDescribe: form.resourceDescribe,
                        deptName: form.deptName,
                        deptId: form.deptId,
                        orgName: form.orgName,
                        orgId: form.orgId
                    }
                    this.$refs.jobTerminalForm.isEdit = true
                    this.$refs.jobTerminalForm.dialogForm = true
                } else {
                    this.$refs.jobTerminalForm.dialogForm = true
                }
            },
            handleRemove(item) {
                this.$confirm(`是否删除该数据?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteJobTerminal(item.id).then(res => {
                        this.$message({
                            type: 'success',
                            message: `删除成功!`
                        });
                        this.loadData()
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
            }
        },
    }

</script>

<style scoped>


</style>
